package org.meb.speedway.model.event;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Version;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import org.hibernate.annotations.ForeignKey;
import org.meb.speedway.model.registry.Rider;

@Entity
@Table(name = "t_event_rider")
@Getter
@Setter
@ToString
public class EventRider implements Serializable {

	public enum RiderKind {
		HOME, AWAY
	}

	private static final long serialVersionUID = -267332662830003735L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;

	@Version
	private Long version;

	@ManyToOne(optional = false)
	@JoinColumn(name = "event_id")
	@ForeignKey(name = "EVRI_EVNT_FK")
	private Event event;

	@ManyToOne(optional = false)
	@JoinColumn(name = "rider_id")
	@ForeignKey(name = "EVRI_RIDR_FK")
	private Rider rider;

	@Column(name = "rider_kind", nullable = false, length = 10)
	@Enumerated(EnumType.STRING)
	private RiderKind riderKind;
}
